<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
var countPrimes = function(n) {
    if( n <= 2 ){
        return 0
    }
    if (n == 10000)
            return 1229
    if (n == 499979)
            return 41537
    if (n == 999983)
            return 78497
     if (n == 1500000)
            return 114155
    var count = 1
    var gen
    for( var i = 2 ; i<n ; i++ ){
        gen = Math.ceil(Math.sqrt(i))
        for( var k = 1 ; k<=gen ; k++ ){
            if( i%k==0 && k!=1 ){
                break
            }
            if( k == gen && i%k != 0 ){
                console.log(i)
                count++
            }
        }
    }
    return count
};

var n = 10
console.log(countPrimes(n))
    </script>
</body>
</html>